<?php
class Admin_Model_Language extends Zend_Db_Table{
	protected $_name = 'language';
	protected $_primary = 'language_id';
	////////////
	/* select*/
	//////////
	public function getAllLanguages()
	{ // co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/language/route/getAllLanguages");
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;		
	}
	public function getLanguageById($id)
	{ // co dung

		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/language/route/getLanguageById/language_id/".$id);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;		
	}
	public function getLanguageByName($name)
	{ // co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/language/route/getLanguageByName/name/".$name);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;		
	}
	
	////////////
	/* insert*/
	//////////
	public function insertLanguage($data)
	{ // co dung

		$data['route'] = "insertLanguage";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/language", $data);

		return $return->getBody();		
	}
	
	////////////
	/* update*/
	//////////
	public function editDefaultLanguage()
	{ // co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/language/route/editDefaultLanguage");
		return $return->getBody();		
	}	
	
	public function editLanguage($id,$data)
	{ // co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/language/route/editLanguage/id/".urlencode($id)."/name/".urlencode($data['name'])."/code/".urlencode($data['code'])."/image/".urlencode($data['image'])."/status/".urlencode($data['status'])."/language_default/".urlencode($data['language_default']));
		return $return->getBody();			
	}
	
	////////////
	/* delete*/
	//////////
	public function deleteLanguage($id)
	{ // co dung

		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/language/route/deleteLanguage/id/".$id);
		return $return->getBody();		
	}

}